package com.ebelter.nb.ui.activitys;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.nb.R;
import com.ebelter.nb.ui.fragments.history.H_BC_Fragment;
import com.ebelter.nb.ui.fragments.history.H_XueYa_Fragment;

import java.util.Objects;

import static com.ebelter.nb.ui.activitys.TrendActivity.Trend_TIZHICHENG;
import static com.ebelter.nb.ui.activitys.TrendActivity.Trend_XUEYA;


public class HistoryActivity extends NBBaseActivity implements View.OnClickListener {

    public static final String TAG = "HistoryActivity";
    public static final String KEY = "HistoryActivity_KEY";
    public static final String USER = "HistoryActivity_USER";




    private String currentModifyType;
    private String currentUser;



    private ImageView top_left_iv;
    private TextView top_title_tv;


    @Override
    protected int loadLayoutById() {
        return R.layout.activity_history;
    }


    @Override
    protected void initView() {
        super.initView();
        currentModifyType = getIntent().getStringExtra(KEY);
        currentUser = getIntent().getStringExtra(USER);
        if (!TextUtils.equals(Trend_XUEYA,currentModifyType)&&!TextUtils.equals(Trend_TIZHICHENG,currentModifyType)){
            throw new RuntimeException("参数不对异常");
        }
        LogUtils.i(TAG,"initView------currentModifyType = "+currentModifyType);
        FV();
        setListener();
        replaceFragment(getFragmentByType(currentModifyType),R.id.history_contain_f);

    }


    private void setListener() {
        top_left_iv.setOnClickListener(this);
    }

    private void FV() {
        top_left_iv=findViewById(R.id.top_left_iv);
        TextView top_right_tv = findViewById(R.id.m_righttitle_tv);
        ViewUtils.hideView(top_right_tv);
        top_title_tv=findViewById(R.id.m_title_tv);
    }




    public Fragment getFragmentByType(String currentType){
        Fragment fragment = null;
        String title = "";
        Bundle bundle = new Bundle();
        if (TextUtils.equals(currentModifyType, Trend_XUEYA)){
            fragment=new H_XueYa_Fragment();
            bundle.putString("user",currentUser);
            fragment.setArguments(bundle);
            title=getString_(R.string.xylb);
        }else if (TextUtils.equals(currentModifyType, Trend_TIZHICHENG)){
            title=getString_(R.string.tzhchlb);
            fragment=new H_BC_Fragment();
            bundle.putString("user",currentUser);
            fragment.setArguments(bundle);
        }

        top_title_tv.setText(title);
        return fragment;
    }

    @Override
    protected void initData() {





    }





    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id==R.id.top_left_iv){
            finish();
        }
    }


}
